import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Scanner;

import com.alibaba.fastjson.JSON;

class Solution {
    public int maxRotateFunction(int[] nums) {
        int f = 0, n = nums.length, numSum = Arrays.stream(nums).sum();
        for (int i=0; i<n; i++) {
            f += i * nums[i];
        }
        int res = f;
        for (int i=n-1; i>0; i--) {
            f += numSum - n * nums[i];
            res = Math.max(res, f);
        }
        return res;
    }
}


class MainClass {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in, StandardCharsets.UTF_8.name());
        String line = cin.nextLine();
        int[] nums = JSON.parseObject(line, int[].class);
        Solution solution = new Solution();
        int res = solution.maxRotateFunction(nums);
        System.out.println(res);
    }
}

/*
"""
不理解的地方：
定义nums的旋转函数F为：
F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1]

"""
*/